﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using ShoppingApp2.Common;
using System.Data.SqlClient;
using System.Data;

namespace ShoppingApp2.DAL
{
    /// <summary>
    /// Base class for all DAL classes
    /// </summary>
    public class ModelDAL
    {
        protected Transaction transaction;
        protected string connectionString;
        protected SqlConnection connection;

        public ModelDAL()
        {

        }

        public ModelDAL(string connectionString)
        {
            this.connectionString = connectionString;
            this.connection = new SqlConnection(connectionString);
        }

        public ModelDAL(Transaction transaction)
        {
            this.transaction = transaction;
            this.connection = transaction.Connection;
        }

        /// <summary>
        /// Creates parameter for sql command
        /// </summary>
        /// <param name="name"></param>
        /// <param name="sqlType"></param>
        /// <param name="value"></param>
        /// <returns></returns>
        public SqlParameter CreateParameter(string name, SqlDbType sqlType, object value)
        {
            SqlParameter parameter = new SqlParameter(name, sqlType);
            parameter.Value = (value != null) ? value : DBNull.Value;

            return parameter;
        }
    }
}